// pages/addMembers/addMembers.js
var app=getApp()

var QQMapWX = require('../../../qqmap-wx-jssdk.min');
var qqmapsdk



Page({

    /**
     * 页面的初始数据
     */
    data: {
        name:"",
        gender:1,
        region: [],
        phone:"",
        workTypeObj:  {
          workIndex:1,
          workType:'瓦工'
        },
        workTypeIndex:0,
        workTypeList:[
          {
            workIndex:1,
            workType:'瓦工'
          }
          ,
          {
            workIndex:2,
            workType:'美缝工'
          },
          {
            workIndex:3,
            workType:'清洁工'
          }
          ],
        isabounttype:false,
        service:[],
        headerImage:"https://shunhui.at1984.com:8443/resource/userfiles/shunhui/shunhui_user_head.png"
    },


// 添加瓦工时类别
radioworkType(e) {
  this.setData({
    addtype: e.detail.value,
    workTypeObj:this.data.workTypeList[e.detail.value]
  })

},


    fakeCallback(){},
    // 28.瓦工详情
    getBricklayDetails(bricklayId){
      wx.showLoading({
        title: '加载中',
        
      mask: true //显示透明蒙层 防止触摸穿透
      })
      let t=this
      wx.request({
        url: app.globalData.Interfaceurl + 'getBricklayDetails',
        method: "post",
        header: {
          "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
        },
        data: {
          userId: app.globalData.userId,
          bricklayId: bricklayId,
         
        },
        success: res => {
          wx.hideLoading()
          console.log(res)
        if(res.data.result==0){
            let bricklayObj=t.data.bricklayObj
            let bricklay=res.data.bricklay
            bricklayObj.name=bricklay.name
            bricklayObj.mobile=bricklay.mobile
            bricklayObj.sex=bricklay.sex
            bricklayObj.province=bricklay.province
            bricklayObj.city=bricklay.city
            bricklayObj.area=bricklay.area
            bricklayObj.beginWorkDate=bricklay.beginWorkDate
            bricklayObj.contractProof=bricklay.contractProof
            bricklayObj.workFlag=bricklay.workFlag
            bricklayObj.workProof=bricklay.workProof
            bricklayObj.trainFlag=bricklay.trainFlag
            bricklayObj.trainProof=bricklay.trainProof
       
            let workType=""
            if(bricklay.workType==1){
              workType="瓦工"
            }else if(bricklay.workType==2){
              workType="美缝工"
            }else if(bricklay.workType==3){
              workType="清洁工"
            }
         let  workTypeObj={workType:workType,workIndex:bricklay.workType}
            this.setData({
              bricklayObj:bricklayObj,
              headerImage:bricklay.image,
              gender:bricklay.sex,
              name:bricklay.name,
              phone:bricklay.mobile,
              region:[bricklay.province,bricklay.city,bricklay.area],
              service:bricklay.beginWorkDate,
              workType:bricklay.workType,
              workTypeObj:workTypeObj
            })
        }else{
          wx.showToast({
            title:res.data.message ,
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
        }
        },
        fail: err => {
          wx.showToast({
            title: '请求失败',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
        }
      })
    },
    // showabounttype(e){
    //   // this.setData({
    //   //   isabounttype:!this.data.isabounttype
    //   //  })
    // },
    bindabounttype(e){
      console.log(e)
      this.setData({
        workTypeObj:this.data.workTypeList[e.detail.value],
        workTypeIndex:e.detail.value
      })
    },
    bindRegionChange(e){
     this.setData({
      region:e.detail.value
     })
    },
    bindRegionChangeservice(e){
      this.setData({
        service:e.detail.value
       })
    },
    bindPlone(e){
      console.log(e)
      let phone=e.detail.value
      let phoneCodeVerification = /^[1][0-9]{10}$/;
      if(!phoneCodeVerification.test(phone)){
        wx.showToast({
          title: '您输入手机号码输入不正确',
          duration: 2500, //持续的时间
          icon: 'none', //图标
      })
      this.setData({
        phone:""
      })
      }else{

      }

    },
    next(){


      if(this.data.name==''){
        wx.showToast({
          title: '请输入瓦工姓名',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
        return
      }

      if(this.data.phone==''){
        wx.showToast({
          title: '请输入瓦工手机号',
          duration: 2500, //持续的时间
            icon: 'none', //图标
        })
        return
      }

      if(this.data.service==''){
        wx.showToast({
          title: '请输入瓦工的工龄',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
        return
      }

      let bricklayObj=this.data.bricklayObj
      bricklayObj.name=this.data.name,
      bricklayObj.mobile=this.data.phone,
      bricklayObj.province=this.data.region[0],
      bricklayObj.city=this.data.region[1],
      bricklayObj.area=this.data.region[2],
      bricklayObj.sex=this.data.gender,
      bricklayObj.workTypeObj=this.data.workTypeObj,
      bricklayObj.beginWorkDate=this.data.service




      wx.navigateTo({
        url: '/supervisor/pages/uploadBricklayer/uploadBricklayer?bricklayObj='+JSON.stringify(bricklayObj),
      })
    },
    radioChange(e){
        this.setData({
            gender:e.detail.value
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      if(options.typeindex){
        this.setData({
          addtype:options.typeindex,
          workTypeObj:this.data.workTypeList[options.typeindex]
        })
      }
      let t=this
       // 实例化API核心类
       qqmapsdk = new QQMapWX({
        key: 'INUBZ-UKHCJ-KS5FI-FDQMU-TXCXV-ZHFSH'
      });
      wx.getLocation({
        type: 'wgs84',
        success: (res) => {
          this.setData({
            latitude_value: res.latitude,
            longitude_value: res.longitude
          })
          qqmapsdk.reverseGeocoder({
            location: {
              latitude: this.data.latitude_value,
              longitude: this.data.longitude_value
            },
            success: (res) => {//成功后的回调
              var city = res.result.ad_info.city;
              // console.log(res)
            t.setData({
              region:[res.result.address_component.province,res.result.address_component.city,res.result.address_component.district]
            })
            }
          })
        }
      })
      var datse = new Date();
      var year = datse.getFullYear(); //  返回的是年份
      var month = datse.getMonth() + 1; //  返回的月份上个月的月份，记得+1才是当月
      month=month>=10?month:"0"+month
      var day = datse.getDate(); //  返回的是几号
      day=day>=10?day:"0"+day
      this.setData({
        service:year+"-"+month,
      })
      if(options.id){
        this.setData({
          bricklayObj:{
            bricklayId:options.id
          }
        })
        this.getBricklayDetails(options.id)
      } else{
        this.setData({
          bricklayObj:{
            bricklayId:''
          }
        })
      }

      


      if(options.todo){
        this.setData({
            todo:options.todo
        })
      }
     
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})